package cn.tedu.springmvc.global;

import org.springframework.web.bind.annotation.ExceptionHandler;

import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
   @ExceptionHandler({
           NullPointerException.class,
           ClassCastException.class
   })
    public  String handleNullPointerException(Throwable e){
       e.printStackTrace();
       return "Error,NullPointerException or ClassCastException!";
   }

    @ExceptionHandler(NumberFormatException.class)
    public  String handleNumberFormatException(Throwable e){
        e.printStackTrace();
        return "Error,numberFormatException";
    }

    @ExceptionHandler(Throwable.class) //这个方法必须写
    public String handleThrowable(Throwable e){
        e.printStackTrace();

       return "Error, Throwable";
    }



}
